﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using bdtheque.data.poco;
using bdtheque.data.enums;

namespace bdtheque.business.bo
{
    public static class POCOFactory
    {
        public static User CreateUser(string identityProvider, string nameIdentifier, string firstName, string lastName,
            DateTime? birthDate, string comment, string adresse1, string adresse2, string postalCode, string region,
            string city, string country, string telephone, string email, UserRole userRole)
        {
            // Create new Default Profile
            var newProfile = CreateProfile("Default");

            // Add parameters with identity information to the new default profile
            newProfile.ParameterList.Add(CreateParameter(identityProvider, nameIdentifier));            

            // Add Superuser for testing purposes
            // TODO: Delete in the future
            if (email.ToLower() == "admin@bdtheque.cloudapp.net")
                userRole = UserRole.Administrator;

            // Create new User and link with his Default Profile and his UserCollection
            var newUser = Factory.GetInstance.Create<User>();
            newUser.Id = 1;
            newUser.FirstName = firstName;
            newUser.LastName = lastName;
            newUser.BirthDate = birthDate;
            newUser.Comment = comment;
            newUser.Address1 = adresse1;
            newUser.Address2 = adresse2;
            newUser.PostalCode = postalCode;
            newUser.Region = region;
            newUser.City = city;
            newUser.Country = country;
            newUser.Telephone = telephone;
            newUser.Email = email;
            newUser.Role = userRole;
            newUser.Profile = newProfile;
            newUser.UserCollection = CreateUserCollection("Default");

            return newUser;
        }

        public static Profile CreateProfile(string profileName)
        {
            var newProfile = Factory.GetInstance.Create<Profile>();
            newProfile.Id = 1;
            newProfile.Name = profileName;
            newProfile.ParameterList = Factory.GetInstance.Create<List<bdtheque.data.poco.Parameter>>();

            return newProfile;
        }

        public static Parameter CreateParameter(string parameterName, string parameterValue)
        {
            var newParameter = Factory.GetInstance.Create<Parameter>();
            newParameter.Id = 1;
            newParameter.Name = parameterName;
            newParameter.Value = parameterValue;

            return newParameter;
        }

        public static UserCollection CreateUserCollection(string userCollectionName)
        {
            var newUserCollection = Factory.GetInstance.Create<UserCollection>();
            newUserCollection.Id = 1;
            newUserCollection.Name = userCollectionName;
            newUserCollection.ComicList = new List<Comic>();
            newUserCollection.ComicSeries = new List<ComicSeries>();

            return newUserCollection;
        }

        public static Comic CreateComic(string comicName, string comment, ComicGenre comicGenre, string imageUri,
            Language comicLanguage, decimal price, DateTime? publishDate, Author author, Publisher publisher)
        {            
            // Create new User and link with an author and a publisher
            var newComic = Factory.GetInstance.Create<Comic>();
            newComic.Id = 1;
            newComic.Name = comicName;
            newComic.Comment = comment;
            newComic.Genre = comicGenre;
            newComic.ImageUri = imageUri;
            newComic.Language = comicLanguage;
            newComic.Price = price;
            newComic.PublishDate = publishDate;
            newComic.Author = author;
            newComic. Publisher = publisher;

            return newComic;
        }

        public static ComicSeries CreateComicSeries(string comicSeriesName, string comment, ComicGenre comicGenre, string imageUri,
            Language comicLanguage, decimal price, DateTime? publishDate, Author author, Publisher publisher)
        {
            // Create new User and link with an author and a publisher
            var newComicSeries = Factory.GetInstance.Create<ComicSeries>();
            newComicSeries.Id = 1;
            newComicSeries.Name = comicSeriesName;
            newComicSeries.Comment = comment;
            newComicSeries.Genre = comicGenre;
            newComicSeries.ImageUri = imageUri;
            newComicSeries.Language = comicLanguage;
            newComicSeries.Price = price;
            newComicSeries.PublishDate = publishDate;
            newComicSeries.Author = author;
            newComicSeries.Publisher = publisher;
            newComicSeries.ComicList = new List<Comic>();

            return newComicSeries;
        }

        public static Author CreateAuthor(string artistName, string comment, DateTime? birthDate, DateTime? deathDate,
            string country, string firstName, string lastName)
        {
            // Create new Author
            var newAuthor = Factory.GetInstance.Create<Author>();
            newAuthor.Id = 1;
            newAuthor.ArtistName = artistName;
            newAuthor.BirthDate = birthDate;
            newAuthor.DeathDate = deathDate;
            newAuthor.Comment = comment;
            newAuthor.Country = country;
            newAuthor.FirstName = firstName;
            newAuthor.LastName = lastName;

            return newAuthor;
        }

        public static Publisher CreatePublisher(string publisherName, string adresse1, string adresse2, string city,
            string country, string email, string postalCode, string region, string telephone, string webSite)
        {
            // Create new Publisher
            var newPublisher = Factory.GetInstance.Create<Publisher>();
            newPublisher.Id = 1;
            newPublisher.Name = publisherName;
            newPublisher.Address1 = adresse1;
            newPublisher.Address2 = adresse2;
            newPublisher.City = city;
            newPublisher.Country = country;
            newPublisher.Email = email;
            newPublisher.PostalCode = postalCode;
            newPublisher.Region = region;
            newPublisher.Telephone = telephone;
            newPublisher.Website = webSite;

            return newPublisher;
        }
    }
}
